/********************************************************************
	File :			Server.h
	Creation date :	2010/6/27
		
	License :			Copyright 2010 Ahmed Charfeddine, http://www.pushframework.com

				   Licensed under the Apache License, Version 2.0 (the "License");
				   you may not use this file except in compliance with the License.
				   You may obtain a copy of the License at
				
					   http://www.apache.org/licenses/LICENSE-2.0
				
				   Unless required by applicable law or agreed to in writing, software
				   distributed under the License is distributed on an "AS IS" BASIS,
				   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
				   See the License for the specific language governing permissions and
				   limitations under the License.
	
	
*********************************************************************/
#ifndef Server__INCLUDED
#define Server__INCLUDED

#pragma once

#include "PushFramework.h"

namespace PushFramework{

	typedef struct Version
	{
		unsigned int major;
		unsigned int minor;
		unsigned int changeList;
		unsigned int monitorProtocolVer;
	}Version;

        class Exception : public std::exception
  {
  public:
    std::string s;
            Exception(std::string ss) : s(ss) {
            }
            ~Exception()throw (){
            }
            const char* what() const throw () {
                return s.c_str();
            }
  };



  


	
	


	class ServerImpl;
	class Protocol;
	class ClientFactory;
	class Service;
	class BroadcastManager;
	class OutgoingPacket;
	struct ListenerOptions;

	class PUSHFRAMEWORK_API Server
	{
	public:
		Server();
		~Server(void);
		void setProtocol(Protocol* pProtocol);
		void setClientFactory(ClientFactory* pClientFactory);


		void addBlockedIPRange(const char* ipStart, const char* ipStop);
		void addPermitIPRange(const char* ipStart, const char* ipStop);


		bool createListener(int port, ListenerOptions* pOptions = NULL);

		void setMaxConnections(int nMaxConnections);

		void enableRemoteMonitor(short sPort, const char* password);
		void enableProfiling(unsigned int samplingRate);
		void disableProfiling();
		
		void setWorkerCount(int workerCount);
		void registerService(unsigned int serviceId, Service* pService, const char* serviceName);
		void start(bool startInSeparateThread = false);
		void stop();
		void pause();
		void resume();
		virtual bool handleMonitorRequest(const char* command, char* lpOut);
		ClientFactory* getClientFactory();
		BroadcastManager* getBroadcastManager();

		void setServerInfos(const char* serverName);

		void setLoginExpiryDuration(unsigned int uLoginExpireDuration);
		void getVersion(Version& ver);

		virtual void* workerThreadBegin();
		virtual void workerThreadEnd(void*);

		virtual OutgoingPacket* getTestPacket();

		virtual void disposeOutgoingPacket(OutgoingPacket* pPacket) = 0;

	private:
		ServerImpl* pImpl;
	};
}

#endif // Server__INCLUDED
